/**
 * 自定义js，依赖于jquery和vue
 * 版本号：1.1
 */
let eventHub = new Vue({
    data: {
        empCount: 0
    }
});
/*
 *  全选按钮
 */
eventHub.$on('allCheck', function (data) {
    let $checkAll = $("#checkAll");
    let $check = $(".check");
    if ($checkAll.is(":checked")) {
        $check.each(function () {
            this.checked = true;
        });
    } else {
        $check.each(function () {
            this.checked = false;
        });
    }
});
/**
 * 判断是否是全部选中状态。
 */
eventHub.$on('isCheckAll', function (data) {
    let $checkAll = $("#checkAll");
    let $check = $(".check");
    let flag = true;
    $check.each(function () {
        if (!this.checked) {
            flag = false;
        }
    });
    $checkAll[0].checked = flag;
});

/**
 * 取消复选框所有选中状态
 */
eventHub.$on('closeCheckAll', function (data) {
    $("#checkAll")[0].checked = false;
    $(".check").each(function () {
        this.checked = false;
    });
});

/**
 * 批量删除id拼接
 */
eventHub.$on('delAll', function (url) {
    let ids = "";
    $(".check").each(function () {
        if (this.checked) {
            ids += ',' + this.value;
        }
    });
    if (ids == "") return;
    $.ajax({
        type: "post",
        url: url,
        data: {"ids": ids},
        dataType: "json",
        async:false,
        success: function (json) {
            eventHub.empCount = json.empCount;
        }
    });
});

/**
 * 点击表格行时，选中第一个复选框
 */
eventHub.$on('trCheck', function (event) {
    let check = event.target.parentNode.firstElementChild.firstElementChild;
    check.checked = !check.checked;
});

